namespace AesonIdentityLibrary.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class h : DbMigration
    {
        public override void Up()
        {
            DropColumn("dbo.ClientApplications", "GuId");
            DropColumn("dbo.UserAuthorizationAssignations", "GuId");
            DropColumn("dbo.UserClaims", "GuId");
            DropColumn("dbo.ApplicationUsers", "GuId");
            DropColumn("dbo.UserClientAppAssignations", "GuId");
            AlterStoredProcedure(
                "dbo.ClientApplication_Insert",
                p => new
                    {
                        ApplicationCode = p.String(),
                        ApplicationDescription = p.String(),
                        ApplicationSecret = p.String(),
                        DateCreate = p.DateTime(),
                        DateModified = p.DateTime(),
                        UserCreated = p.String(),
                        UserModified = p.String(),
                    },
                body:
                    @"INSERT [dbo].[ClientApplications]([ApplicationCode], [ApplicationDescription], [ApplicationSecret], [DateCreate], [DateModified], [UserCreated], [UserModified])
                      VALUES (@ApplicationCode, @ApplicationDescription, @ApplicationSecret, @DateCreate, @DateModified, @UserCreated, @UserModified)
                      
                      DECLARE @Id int
                      SELECT @Id = [Id]
                      FROM [dbo].[ClientApplications]
                      WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()
                      
                      SELECT t0.[Id]
                      FROM [dbo].[ClientApplications] AS t0
                      WHERE @@ROWCOUNT > 0 AND t0.[Id] = @Id"
            );
            
            AlterStoredProcedure(
                "dbo.ClientApplication_Update",
                p => new
                    {
                        Id = p.Int(),
                        ApplicationCode = p.String(),
                        ApplicationDescription = p.String(),
                        ApplicationSecret = p.String(),
                        DateCreate = p.DateTime(),
                        DateModified = p.DateTime(),
                        UserCreated = p.String(),
                        UserModified = p.String(),
                    },
                body:
                    @"UPDATE [dbo].[ClientApplications]
                      SET [ApplicationCode] = @ApplicationCode, [ApplicationDescription] = @ApplicationDescription, [ApplicationSecret] = @ApplicationSecret, [DateCreate] = @DateCreate, [DateModified] = @DateModified, [UserCreated] = @UserCreated, [UserModified] = @UserModified
                      WHERE ([Id] = @Id)"
            );
            
            AlterStoredProcedure(
                "dbo.UserAuthorizationAssignation_Insert",
                p => new
                    {
                        UserId = p.Int(),
                        CLaimsId = p.Int(),
                        ClientApplicationId = p.Int(),
                        DateCreate = p.DateTime(),
                        DateModified = p.DateTime(),
                        UserCreated = p.String(),
                        UserModified = p.String(),
                    },
                body:
                    @"INSERT [dbo].[UserAuthorizationAssignations]([UserId], [CLaimsId], [ClientApplicationId], [DateCreate], [DateModified], [UserCreated], [UserModified])
                      VALUES (@UserId, @CLaimsId, @ClientApplicationId, @DateCreate, @DateModified, @UserCreated, @UserModified)
                      
                      DECLARE @Id int
                      SELECT @Id = [Id]
                      FROM [dbo].[UserAuthorizationAssignations]
                      WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()
                      
                      SELECT t0.[Id]
                      FROM [dbo].[UserAuthorizationAssignations] AS t0
                      WHERE @@ROWCOUNT > 0 AND t0.[Id] = @Id"
            );
            
            AlterStoredProcedure(
                "dbo.UserAuthorizationAssignation_Update",
                p => new
                    {
                        Id = p.Int(),
                        UserId = p.Int(),
                        CLaimsId = p.Int(),
                        ClientApplicationId = p.Int(),
                        DateCreate = p.DateTime(),
                        DateModified = p.DateTime(),
                        UserCreated = p.String(),
                        UserModified = p.String(),
                    },
                body:
                    @"UPDATE [dbo].[UserAuthorizationAssignations]
                      SET [UserId] = @UserId, [CLaimsId] = @CLaimsId, [ClientApplicationId] = @ClientApplicationId, [DateCreate] = @DateCreate, [DateModified] = @DateModified, [UserCreated] = @UserCreated, [UserModified] = @UserModified
                      WHERE ([Id] = @Id)"
            );
            
            AlterStoredProcedure(
                "dbo.UserClaim_Insert",
                p => new
                    {
                        Name = p.String(),
                        Description = p.String(),
                        Type = p.Int(),
                        DateCreate = p.DateTime(),
                        DateModified = p.DateTime(),
                        UserCreated = p.String(),
                        UserModified = p.String(),
                    },
                body:
                    @"INSERT [dbo].[UserClaims]([Name], [Description], [Type], [DateCreate], [DateModified], [UserCreated], [UserModified])
                      VALUES (@Name, @Description, @Type, @DateCreate, @DateModified, @UserCreated, @UserModified)
                      
                      DECLARE @Id int
                      SELECT @Id = [Id]
                      FROM [dbo].[UserClaims]
                      WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()
                      
                      SELECT t0.[Id]
                      FROM [dbo].[UserClaims] AS t0
                      WHERE @@ROWCOUNT > 0 AND t0.[Id] = @Id"
            );
            
            AlterStoredProcedure(
                "dbo.UserClaim_Update",
                p => new
                    {
                        Id = p.Int(),
                        Name = p.String(),
                        Description = p.String(),
                        Type = p.Int(),
                        DateCreate = p.DateTime(),
                        DateModified = p.DateTime(),
                        UserCreated = p.String(),
                        UserModified = p.String(),
                    },
                body:
                    @"UPDATE [dbo].[UserClaims]
                      SET [Name] = @Name, [Description] = @Description, [Type] = @Type, [DateCreate] = @DateCreate, [DateModified] = @DateModified, [UserCreated] = @UserCreated, [UserModified] = @UserModified
                      WHERE ([Id] = @Id)"
            );
            
            AlterStoredProcedure(
                "dbo.ApplicationUser_Insert",
                p => new
                    {
                        PasswordHash = p.String(),
                        SecurityStamp = p.String(),
                        UserName = p.String(),
                        EMail = p.String(),
                        DateCreate = p.DateTime(),
                        DateModified = p.DateTime(),
                        UserCreated = p.String(),
                        UserModified = p.String(),
                    },
                body:
                    @"INSERT [dbo].[ApplicationUsers]([PasswordHash], [SecurityStamp], [UserName], [EMail], [DateCreate], [DateModified], [UserCreated], [UserModified])
                      VALUES (@PasswordHash, @SecurityStamp, @UserName, @EMail, @DateCreate, @DateModified, @UserCreated, @UserModified)
                      
                      DECLARE @Id int
                      SELECT @Id = [Id]
                      FROM [dbo].[ApplicationUsers]
                      WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()
                      
                      SELECT t0.[Id]
                      FROM [dbo].[ApplicationUsers] AS t0
                      WHERE @@ROWCOUNT > 0 AND t0.[Id] = @Id"
            );
            
            AlterStoredProcedure(
                "dbo.ApplicationUser_Update",
                p => new
                    {
                        Id = p.Int(),
                        PasswordHash = p.String(),
                        SecurityStamp = p.String(),
                        UserName = p.String(),
                        EMail = p.String(),
                        DateCreate = p.DateTime(),
                        DateModified = p.DateTime(),
                        UserCreated = p.String(),
                        UserModified = p.String(),
                    },
                body:
                    @"UPDATE [dbo].[ApplicationUsers]
                      SET [PasswordHash] = @PasswordHash, [SecurityStamp] = @SecurityStamp, [UserName] = @UserName, [EMail] = @EMail, [DateCreate] = @DateCreate, [DateModified] = @DateModified, [UserCreated] = @UserCreated, [UserModified] = @UserModified
                      WHERE ([Id] = @Id)"
            );
            
            AlterStoredProcedure(
                "dbo.UserClientAppAssignation_Insert",
                p => new
                    {
                        Blocked = p.Boolean(),
                        BlockingDate = p.String(),
                        UserBlockingName = p.String(),
                        AppId = p.Int(),
                        UserId = p.Int(),
                        DateCreate = p.DateTime(),
                        DateModified = p.DateTime(),
                        UserCreated = p.String(),
                        UserModified = p.String(),
                    },
                body:
                    @"INSERT [dbo].[UserClientAppAssignations]([Blocked], [BlockingDate], [UserBlockingName], [AppId], [UserId], [DateCreate], [DateModified], [UserCreated], [UserModified])
                      VALUES (@Blocked, @BlockingDate, @UserBlockingName, @AppId, @UserId, @DateCreate, @DateModified, @UserCreated, @UserModified)
                      
                      DECLARE @Id int
                      SELECT @Id = [Id]
                      FROM [dbo].[UserClientAppAssignations]
                      WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()
                      
                      SELECT t0.[Id]
                      FROM [dbo].[UserClientAppAssignations] AS t0
                      WHERE @@ROWCOUNT > 0 AND t0.[Id] = @Id"
            );
            
            AlterStoredProcedure(
                "dbo.UserClientAppAssignation_Update",
                p => new
                    {
                        Id = p.Int(),
                        Blocked = p.Boolean(),
                        BlockingDate = p.String(),
                        UserBlockingName = p.String(),
                        AppId = p.Int(),
                        UserId = p.Int(),
                        DateCreate = p.DateTime(),
                        DateModified = p.DateTime(),
                        UserCreated = p.String(),
                        UserModified = p.String(),
                    },
                body:
                    @"UPDATE [dbo].[UserClientAppAssignations]
                      SET [Blocked] = @Blocked, [BlockingDate] = @BlockingDate, [UserBlockingName] = @UserBlockingName, [AppId] = @AppId, [UserId] = @UserId, [DateCreate] = @DateCreate, [DateModified] = @DateModified, [UserCreated] = @UserCreated, [UserModified] = @UserModified
                      WHERE ([Id] = @Id)"
            );
            
        }
        
        public override void Down()
        {
            AddColumn("dbo.UserClientAppAssignations", "GuId", c => c.String(nullable: false));
            AddColumn("dbo.ApplicationUsers", "GuId", c => c.String(nullable: false));
            AddColumn("dbo.UserClaims", "GuId", c => c.String(nullable: false));
            AddColumn("dbo.UserAuthorizationAssignations", "GuId", c => c.String(nullable: false));
            AddColumn("dbo.ClientApplications", "GuId", c => c.String(nullable: false));
            throw new NotSupportedException("Scaffolding create or alter procedure operations is not supported in down methods.");
        }
    }
}
